package com.sgb.kjwl.view.ui.activity.self.packers;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivitySelfTeamOfferAddBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.swgk.core.util.PickSelectEntity;;
import com.sgb.kjwl.model.entity.self.SelfTeamIntroduceEntity;
import com.sgb.kjwl.model.entity.self.SelfTeamOfferEntity;
import com.sgb.kjwl.model.entity.transport.MapLongAndLatEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.kjwl.view.ui.adapter.self.packers.SelfTeamOfferDeviceAdapter;
import com.sgb.kjwl.view.ui.adapter.self.packers.SelfTeamOfferMaterialAdapter;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.sgb.kjwl.viewmodel.self.packers.SelfTeamOfferEditModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 *
 * @author WYJ
 * @date 2020/8/28
 * description:添加工种报价编辑
 */
public class SelfTeamOfferEditActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {

    @Inject
    public SelfTeamOfferEditModel mModel;
    private ActivitySelfTeamOfferAddBinding mBind;

    private SelfTeamOfferEntity mEntity;
    private final List<String> mSchemes = new ArrayList<>();

    private SelfTeamOfferMaterialAdapter materialAdapter;
    private SelfTeamOfferDeviceAdapter deviceAdapter;

    /**
     * 一级联动数据
     */
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    /**
     * 二级联动数据
     */
    private final List<List<AddressEntity<List<AddressEntity>>>> opt2 = new ArrayList<>();
    /**三级联动数据
     *
     */
    private final List<List<List<AddressEntity>>> opt3 = new ArrayList<>();

    private Thread thread;
    private static final int MSG_LOAD_DATA = 0x0001;
    private static final int MSG_LOAD_SUCCESS = 0x0002;
    private boolean isLoaded = false;


    private List<PickSelectEntity> pickWorkType;
    private List<PickSelectEntity> TeamNamePop;

    private int cityPosition1;
    private int cityPosition2;
    private int cityPosition3;

    private static final int REQUEST_CODE_MATERIAL = 10021;
    private static final int REQUEST_CODE_DEVICE = 10022;

    public static void start(AppActivity context, SelfTeamOfferEntity entity, int code) {
        Intent intent = new Intent(context, SelfTeamOfferEditActivity.class);
        intent.putExtra(AppConstant.EXTRA_ENTITY, entity);
        context.startActivityForResult(intent, code);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder()
                .appComponent(appComponent)
                .selfModule(new SelfModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mEntity == null) {
            mEntity = new SelfTeamOfferEntity();
            mEntity.setId("0");
            mActionBar.setTitle(String.format("添加%s", getResources().getString(R.string.self_team6)));
        } else {
            mActionBar.setTitle(String.format("编辑%s", getResources().getString(R.string.self_team6)));
            showWorkType();
            mModel.detailTeamPrice(mEntity);
        }
    }

    @Override
    protected void initView() {
        mEntity = (SelfTeamOfferEntity) getIntent().getSerializableExtra(AppConstant.EXTRA_ENTITY);
        mBind = DataBindingUtil.setContentView(this, R.layout.activity_self_team_offer_add);
        mBind.setViewModel(mEntity);
        mBind.btnRelease.setOnClickListener(this);
        mBind.etType.setOnWholeItemClickListener(this);
        mBind.etScheme.setOnWholeItemClickListener(this);
        mBind.etAddress.setOnWholeItemClickListener(this);
        mBind.etName.setOnWholeItemClickListener(this);
        mBind.etAddressDetail.setOnClickListener(this);
        mBind.etCustomerService.setOnWholeItemClickListener(this);
        mBind.etTeamName.setOnWholeItemClickListener(this);
        mBind.tvAddMaterial.setOnClickListener(this);
        mBind.tvAddDevice.setOnClickListener(this);
        mBind.etContentPhone.getContent_edt().setInputType(InputType.TYPE_CLASS_PHONE);
        mBind.etContentPhone.setInfilterType(ItemInputTextView.TYPE_PHONE);
        mBind.etUnitMoney.getContent_edt().setInputType(InputType.TYPE_CLASS_NUMBER);
        mBind.etAddressDetail.setSingleLine(true);
        // 0:包含 1：不包含 2：两种
        mSchemes.add("包含辅材");
        mSchemes.add("包含设备");
        mSchemes.add("包含辅材和设备");
        mSchemes.add("不包含辅材和设备");

        materialAdapter = new SelfTeamOfferMaterialAdapter(this, null, Glide.with(this));
        mBind.listMaterial.setLayoutManager(new LinearLayoutManager(this));
        mBind.listMaterial.setAdapter(materialAdapter);
        materialAdapter.setListener(new SelfTeamOfferMaterialAdapter.ClickResultListener() {
            @Override
            public void onEdit(SelfTeamOfferEntity.MaterialListDTO entity, int position) {
                SelfOfferMaterialEditActivity.start(SelfTeamOfferEditActivity.this, entity, position, REQUEST_CODE_MATERIAL);
            }

            @Override
            public void onDelete(int position) {
                mEntity.getMaterialList().remove(position);
                materialAdapter.removeItem(position);
            }
        });
        deviceAdapter = new SelfTeamOfferDeviceAdapter(this, null, Glide.with(this));
        mBind.listDevice.setLayoutManager(new LinearLayoutManager(this));
        mBind.listDevice.setAdapter(deviceAdapter);
        deviceAdapter.setListener(new SelfTeamOfferDeviceAdapter.ClickResultListener() {
            @Override
            public void onEdit(SelfTeamOfferEntity.EquipmentListDTO entity, int position) {
                SelfOfferDeviceEditActivity.start(SelfTeamOfferEditActivity.this, entity, position, REQUEST_CODE_DEVICE);
            }

            @Override
            public void onDelete(int position) {
                mEntity.getEquipmentList().remove(position);
                deviceAdapter.removeItem(position);
            }
        });

        mModel.getCategoryData("", null);
    }

    /**
     * 编辑请求详情回调
     * @param entity 详情的对象
     */
    public void updateOfferEntity(SelfTeamOfferEntity entity) {
        if (entity != null) {
            mEntity = entity;
            mBind.setViewModel(mEntity);
            showWorkType();
            updateQuotationScheme(entity.getHasMaterial());
            if (entity.getMaterialList() != null && entity.getMaterialList().size() > 0) {
                materialAdapter.setDatas(entity.getMaterialList());
            }
            if (entity.getEquipmentList() != null && entity.getEquipmentList().size() > 0) {
                deviceAdapter.setDatas(entity.getEquipmentList());
            }
            mBind.etAddress.setContent(entity.getProvinceName()+entity.getCityName()+entity.getAreaName());
        }
    }

    public SelfTeamOfferEntity getEntity() {
        return mEntity;
    }

    public void updateQuotationScheme(int options1) {
        mBind.etScheme.setContent(mSchemes.get(options1));
        mEntity.setHasMaterial(options1);
        // 0:包含辅材 1：包含设备 2：包含辅材和设备 3：不包含辅材和设备
        switch (options1) {
            case 0:
                mBind.llMaterial.setVisibility(View.VISIBLE);
                mBind.llDevice.setVisibility(View.GONE);
                break;
            case 1:
                mBind.llMaterial.setVisibility(View.GONE);
                mBind.llDevice.setVisibility(View.VISIBLE);
                break;
            case 2:
                mBind.llMaterial.setVisibility(View.VISIBLE);
                mBind.llDevice.setVisibility(View.VISIBLE);
                break;
            case 3:
                mBind.llMaterial.setVisibility(View.GONE);
                mBind.llDevice.setVisibility(View.GONE);
                break;
            default:
                break;
        }
    }

    @Override
    public void onMultiClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_release) {
            if (TextUtils.isEmpty(mBind.etName.getContent())) {
                MToast.showToast(this, mBind.etName.getContent_edt().getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etType.getContent())) {
                MToast.showToast(this, mBind.etType.getContent_edt().getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etContent.getContent())) {
                MToast.showToast(this, mBind.etContent.getContent_edt().getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etContentPhone.getContent())) {
                MToast.showToast(this, mBind.etContentPhone.getContent_edt().getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etScheme.getContent())) {
                MToast.showToast(this, mBind.etScheme.getContent_edt().getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etUnit.getContent())) {
                MToast.showToast(this, mBind.etUnit.getContent_edt().getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etUnitMoney.getContent())) {
                MToast.showToast(this, mBind.etUnitMoney.getContent_edt().getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etAddress.getContent())) {
                MToast.showToast(this, mBind.etAddress.getContent_edt().getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etAddressDetail.getText())) {
                MToast.showToast(this, mBind.etAddressDetail.getHint().toString());
                return;
            }
            if (TextUtils.isEmpty(mBind.etPrinciple.getEditContent())) {
                MToast.showToast(this, "请输入报价详情");
                return;
            }
            if (!CheckUtils.isMobile(mBind.etContentPhone.getContent().trim())) {
                MToast.showToast(this, "请填写正确的联系电话");
                return;
            }
            // 0:包含辅材 1：包含设备 2：包含辅材和设备 3：不包含辅材和设备
            switch (mEntity.getHasMaterial()) {
                case 0:
                    if (materialAdapter.getItemCount() == 0) {
                        MToast.showToast(this, "请添加辅材");
                        return;
                    }
                    if (mEntity.getEquipmentList() != null && mEntity.getEquipmentList().size() > 0) {
                        mEntity.getEquipmentList().clear();
                    }
                    break;
                case 1:
                    if (deviceAdapter.getItemCount() == 0) {
                        MToast.showToast(this, "请添加设备信息");
                        return;
                    }
                    if (mEntity.getMaterialList() != null && mEntity.getMaterialList().size() > 0) {
                        mEntity.getMaterialList().clear();
                    }
                    break;
                case 2:
                    if (materialAdapter.getItemCount() == 0) {
                        MToast.showToast(this, "请添加辅材");
                        return;
                    }
                    if (deviceAdapter.getItemCount() == 0) {
                        MToast.showToast(this, "请添加设备信息");
                        return;
                    }
                    break;
                case 3:
                    if (mEntity.getMaterialList() != null && mEntity.getMaterialList().size() > 0) {
                        mEntity.getMaterialList().clear();
                    }
                    if (mEntity.getEquipmentList() != null && mEntity.getEquipmentList().size() > 0) {
                        mEntity.getEquipmentList().clear();
                    }
                    break;
                default:
                    break;
            }
            mEntity.setContact(mBind.etContent.getContent());
            mEntity.setContactPhone(mBind.etContentPhone.getContent());
            mEntity.setUnit(mBind.etUnit.getContent());
            mEntity.setTeamName(mBind.etTeamName.getContent() + "");
            mEntity.setPrinciple(mBind.etPrinciple.getEditContent());
            mEntity.setPrice(mBind.etUnitMoney.getContent());
            mModel.addTeamPrice(mEntity);
        } else if (id == R.id.tv_add_material) {
            SelfOfferMaterialEditActivity.start(this, null, -1, REQUEST_CODE_MATERIAL);
        } else if (id == R.id.tv_add_device) {
            SelfOfferDeviceEditActivity.start(this, null, -1, REQUEST_CODE_DEVICE);
        } else if (id == R.id.et_address_detail) {
            if (TextUtils.isEmpty(mEntity.getProvinceNo())) {
                MToast.showToast(this, "请先选择所在地区");
            } else {
                mModel.getLocationLL(mEntity.getProvinceNo(), mEntity.getCityNo(), mEntity.getAreaNo());
            }
        }
    }

    @Override
    public void OnWholeItemClick(View view) {
        int id = view.getId();
        if (id == R.id.et_type) {
            mModel.showPop(view);
        } else if (id == R.id.et_scheme) {
            mModel.showSchemesPop(mSchemes);
        } else if (id == R.id.et_address) {
            if (addressEntityList != null) {
                showCityPop();
            } else {
                mModel.getAddressModel();
            }
        } else if (id == R.id.et_name) {
            if (null == pickWorkType) {
                mModel.getWorkType();
            } else {
                showPickWorkTypePop(pickWorkType);
            }
        } else if (id == R.id.et_customer_service) {
            mModel.showCustomerPop();
        } else if (id == R.id.et_teamName) {
            //报价工队：拉去工队列表中数据
            if (null == TeamNamePop) {
                mModel.getNameByComAndUserNo();
            } else {
                showTeamNamePop(TeamNamePop);
            }
        }
    }

    public void showWorkType() {
        String sb = "";
        if (!TextUtils.isEmpty(mEntity.getFirstCategoryName())) {
            sb = mEntity.getFirstCategoryName();
        }
        if (!TextUtils.isEmpty(mEntity.getSecondCategoryName())) {
            sb = mEntity.getSecondCategoryName();
        }
        if (!TextUtils.isEmpty(mEntity.getThirdCategoryName())) {
            sb = mEntity.getThirdCategoryName();
        }
        if (!TextUtils.isEmpty(mEntity.getFourCategoryName())) {
            sb = mEntity.getFourCategoryName();
        }
        if (!TextUtils.isEmpty(mEntity.getFifthCategoryName())) {
            sb = mEntity.getFifthCategoryName();
        }
        if (!TextUtils.isEmpty(mEntity.getSixthCategoryName())) {
            sb =mEntity.getSixthCategoryName();
        }
        if (!TextUtils.isEmpty(sb)) {
            mBind.etType.setContent(sb);
        }
    }

    public void editEntitySuccess() {
        setResult(RESULT_OK, new Intent().putExtra(AppConstant.EXTRA_OBJ, mEntity));
        finish();
    }

    public void showEmpty() {
        mBind.emptyView.setVisibility(View.VISIBLE);
        DialogHelper.dismissProgressDialog();
    }

    //所在地区选择
    public void showAddressPop(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data) {
        this.addressEntityList = data;
        if (isLoaded) {
            showCityPop();
        } else {
            mHandler.sendEmptyMessage(MSG_LOAD_DATA);
        }
    }

    @SuppressWarnings("unchecked")
    public void showCityPop() {
        //条件选择器
        CityPickView cityOption = new CityPickBuilder(SelfTeamOfferEditActivity.this, (options1, options2, options3, v) -> {
            String areaName;
            if (opt3.get(options1).get(options2).get(options3) == null) {
                areaName = "";
            } else {
                areaName = opt3.get(options1).get(options2).get(options3).getName();
                cityPosition3 = options3;
                mEntity.setAreaNo(opt3.get(options1).get(options2).get(options3).getNo());
                mEntity.setAreaName(areaName);
            }
            String content = addressEntityList.get(options1).getName()
                    + opt2.get(options1).get(options2).getName()
                    + areaName;
            mBind.etAddress.setContent(content);

            cityPosition1 = options1;
            cityPosition2 = options2;
            mEntity.setProvinceName(addressEntityList.get(options1).getName());
            mEntity.setProvinceNo(addressEntityList.get(options1).getId());
            mEntity.setCityName(opt2.get(options1).get(options2).getName());
            mEntity.setCityNo(opt2.get(options1).get(options2).getNo());
        }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).setTitleColor(ContextCompat.getColor(this, R.color.color_969696)).build();
        cityOption.setPicker(addressEntityList, opt2, opt3);
        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
        cityOption.setTitleText("选择方案");
        cityOption.show();
    }

    private final Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_LOAD_DATA:
                    if (thread == null) {
                        //如果已创建就不再重新创建子线程了
                        thread = new Thread(() -> {
                            // 子线程中解析省市区数据
                            initJsonData();
                        });
                        thread.start();
                    }
                    break;
                case MSG_LOAD_SUCCESS:
                    showCityPop();
                    isLoaded = true;
                    thread = null;
                    break;
                default:
                    break;
            }
            return false;
        }
    });

    private void initJsonData() {
        //城市列表
        @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
        List<AddressEntity<List<AddressEntity>>> cityList;
        //区域列表
        List<List<AddressEntity>> areaList;
        for (int x = 0; x < addressEntityList.size(); x++) {
            cityList = new ArrayList<>();
            areaList = new ArrayList<>();
            if (mEntity != null && mEntity.getProvinceName() != null && mEntity.getProvinceName().equals(addressEntityList.get(x).getName())) {
                cityPosition1 = x;
            }
            opt2.add(addressEntityList.get(x).getChildren());
            for (int i = 0; i < addressEntityList.get(x).getChildren().size(); i++) {
                cityList.add(addressEntityList.get(x).getChildren().get(i));
                List<AddressEntity> cityAreaList = new ArrayList<>();
                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (addressEntityList.get(x).getChildren().get(i).getChildren() == null
                        || addressEntityList.get(x).getChildren().get(i).getChildren().size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(addressEntityList.get(x).getChildren().get(i).getChildren());
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }
        if (mEntity != null) {
            if (!TextUtils.isEmpty(mEntity.getCityName())) {
                for (int x2 = 0; x2 < opt2.size(); x2++) {
                    if (mEntity.getCityName().equals(addressEntityList.get(cityPosition1).getChildren().get(x2).getName())) {
                        cityPosition2 = x2;
                        break;
                    }
                }
            }
            if (!TextUtils.isEmpty(mEntity.getAreaName())) {
                for (int x3 = 0; x3 < opt3.size(); x3++) {
                    if (mEntity.getAreaName().equals(addressEntityList.get(cityPosition1).getChildren().get(cityPosition2).getChildren().get(x3).getName())) {
                        cityPosition3 = x3;
                        break;
                    }
                }
            }
        }
        mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS);
    }

    public void showPickWorkTypePop(List<PickSelectEntity> list) {
        if (null == pickWorkType) {
            pickWorkType = new ArrayList<>();
            pickWorkType.addAll(list);
        }
        if (pickWorkType.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(SelfTeamOfferEditActivity.this, (options1, options2, options3, v) -> {
                mBind.etName.setContent(pickWorkType.get(options1).getProjectscale());
                mEntity.setTypeWorkName(pickWorkType.get(options1).getProjectscale());
                mEntity.setTypeWork(pickWorkType.get(options1).getNo());
            }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).setTitleColor(ContextCompat.getColor(this, R.color.color_969696)).build();
            projectCategoryOption.setPicker(pickWorkType);
            projectCategoryOption.setSelectOptions(0);
            projectCategoryOption.show();
        }
    }

    public void updateAddress(MapLongAndLatEntity data) {
        if (!TextUtils.isEmpty(data.getLat())) {
            if (!TextUtils.isEmpty(data.getLng())) {
                ActivityJump.jumpToActivityForResult(this, SelectAddressActivity.class,255, Pair.create(SelectAddressActivity.TITLE, "详细地址")
                        ,Pair.create(SelectAddressActivity.HINT, "请输入地址"),Pair.create(SelectAddressActivity.SAVE_TEXT, "确定")
                        ,Pair.create(SelectAddressActivity.LATITUDE, Double.parseDouble(data.getLat())),Pair.create(SelectAddressActivity.LONGTITUDE, Double.parseDouble(data.getLng())));
            }
        }
    }

    /**
     * 咨询客服的回调
     * @param serviceEntity 咨询客服的对象
     */
    public void updateCustomer(PickSelectEntity serviceEntity) {
        mEntity.setImName(serviceEntity.getProjectscale());
        mEntity.setImId(serviceEntity.getNo());
        mBind.etCustomerService.setContent(serviceEntity.getProjectscale());
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        if (requestCode == REQUEST_CODE_MATERIAL) {
            int position = data.getIntExtra("position", -1);
            SelfTeamOfferEntity.MaterialListDTO materialListDTO = (SelfTeamOfferEntity.MaterialListDTO) data.getSerializableExtra("material");
            if (position == -1) {
                if (mEntity.getMaterialList() == null || mEntity.getMaterialList().size() == 0) {
                    List<SelfTeamOfferEntity.MaterialListDTO> listDTOS = new ArrayList<>();
                    listDTOS.add(materialListDTO);
                    mEntity.setMaterialList(listDTOS);
                    materialAdapter.addDatas(listDTOS);
                } else {
                    mEntity.getMaterialList().add(materialListDTO);
                    materialAdapter.addData(materialListDTO);
                }
            } else {
                mEntity.getMaterialList().remove(position);
                mEntity.getMaterialList().add(position, materialListDTO);
                materialAdapter.removeItem(position);
                materialAdapter.addData(materialListDTO, position);
            }
        } else if (requestCode == REQUEST_CODE_DEVICE) {
            int index = data.getIntExtra("position", -1);
            SelfTeamOfferEntity.EquipmentListDTO equipmentListDTO = (SelfTeamOfferEntity.EquipmentListDTO) data.getSerializableExtra("device");
            if (index == -1) {
                if (mEntity.getEquipmentList() == null || mEntity.getEquipmentList().size() == 0) {
                    List<SelfTeamOfferEntity.EquipmentListDTO> listDTOS = new ArrayList<>();
                    listDTOS.add(equipmentListDTO);
                    mEntity.setEquipmentList(listDTOS);
                    deviceAdapter.addDatas(listDTOS);
                } else {
                    mEntity.getEquipmentList().add(equipmentListDTO);
                    deviceAdapter.addData(equipmentListDTO);
                }
            } else {
                mEntity.getEquipmentList().remove(index);
                mEntity.getEquipmentList().add(index, equipmentListDTO);
                deviceAdapter.removeItem(index);
                deviceAdapter.addData(equipmentListDTO, index);
            }
        } else if (requestCode == 255) {
            if (data == null) {
                return;
            }
            setAddressText(data);
        }
    }

    public void setAddressText(Intent data) {
        double lat = data.getDoubleExtra(SelectAddressActivity.LATITUDE, 0);
        double lon = data.getDoubleExtra(SelectAddressActivity.LONGTITUDE, 0);
        String address = data.getStringExtra(SelectAddressActivity.CURRENT_POSITION);
        mEntity.setLongitude(lon + "");
        mEntity.setLatitude(lat + "");
        mBind.etAddressDetail.setText(address);
        mEntity.setAddress(address);
    }

    public void updateIntroduce(SelfTeamIntroduceEntity data) {
        if (data != null) {
            mBind.etTeamName.setContent(data.getTeamName());
        }
    }

    public void showTeamNamePop(List<PickSelectEntity> data) {
        if (null == TeamNamePop) {
            TeamNamePop = new ArrayList<>();
            TeamNamePop.addAll(data);
        }
        if (TeamNamePop.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(SelfTeamOfferEditActivity.this, (options1, options2, options3, v) -> {
                mBind.etTeamName.setContent(TeamNamePop.get(options1).getProjectscale());
                mEntity.setTeamName(TeamNamePop.get(options1).getProjectscale());
            }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).setTitleColor(ContextCompat.getColor(this, R.color.color_969696)).build();
            projectCategoryOption.setPicker(TeamNamePop);
            projectCategoryOption.setTitleText("请选择报价工队");
            projectCategoryOption.setSelectOptions(0);
            projectCategoryOption.show();
        }
    }
}
